home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’90 / Busy Box / Sources / randomDot.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-14  |  1.0 KB  |  50 lines  |  [TEXT/KAHL]

  1. /* file: RandomDot.c    
  2.     puts random dots in its area
  3.     By MGD
  4. */
  5.  
  6. #include "busybox.h"
  7. #define abs(x)    ((x <= 0) ? (-x) : (x))
  8. #define ThruThreshold    150
  9.  
  10. /* Guys: It's possible to put some "file-global" data here if you want to share it
  11.         among all the functions in this file.  It's up to you if you want     */
  12. static Rect    ourRect;
  13. static int16 numThru;
  14. static width, height;
  15.  
  16. void InitRandomDotObj(Rect *drawArea, int16 ID)    {
  17.     /* You can put various stuffages here - i.e. load string resources, init a brick
  18.         picture, oop ack.    */
  19.     
  20.     ourRect = *drawArea;
  21.     numThru = 0;
  22.     width = ourRect.right;
  23.     height = ourRect.bottom;
  24.     SetRect(&ourRect,0, 0, 500, 500);
  25.     
  26. }    /* InitRandomDotObj    */
  27.  
  28.  
  29.  
  30. void DrawRandomDotObj(int16 ID)    {
  31.     static Point whereLast;    /* what the last point drawn was    */
  32.     
  33.     int16    i, j, z;
  34.     
  35.     if (numThru++ > ThruThreshold)    {
  36.         EraseRect(&ourRect);
  37.         numThru = 0;
  38.     }
  39.     MoveTo(whereLast.h, whereLast.v);
  40.     z = Random();
  41.     i = abs(z) % width;
  42.     z = Random();
  43.     j = abs(z) % height;
  44.     LineTo(i,j);
  45.     whereLast.h = i; whereLast.v = j;
  46. }    /* DrawRandomDotObj    */
  47.  
  48.  
  49.  
  50.